import {request} from "./network"

export function getCommonData(){
    // return request({
    //     url: '/pinlun.json'
    // })
    return Promise.resolve(test().data.map((v) => new Common(v)));

}

export function addCommon(postData){
    return request().post('/index.php',postData,{
        headers: { "Content-Type": "multipart/form-data" },
    })
}

export class Common {

    constructor(common){
        this.id = common.id;
        this.rate = parseInt(common.rating);
        this.isAnonymous = parseInt(common.is_anonymous);
        this.addTime = common.add_time;
        this.uname = common.custom_name;
        this.title = common.title;
        this.content = common.content;
        this.likeNum = parseInt(common.likes_num[0].like_num);
        this.isLike = Boolean(common.likes_num[0].selected);
        this.disLikeNum = parseInt(common.likes_num[1].dislike_num);
        this.isDislike = Boolean(common.likes_num[1].selected);
        this.imgs = common.imgs;

        this.LIKE = 0;
        this.DISLIKE = 1;
    }

    changeLike(type){
        if(this.isLike && type==this.LIKE || this.isDislike && type == this.DISLIKE){
            return;
        }
        if(type == this.DISLIKE){
            this.isDislike = true;
            this.disLikeNum += 1;
            if(this.isLike){
                this.likeNum -= 1;
                this.isLike =  false;
            }
        }else{
            this.isLike = true;
            this.likeNum += 1;
            if(this.isDislike){
                this.disLikeNum -= 1;
                this.isDislike =  false;
            }
        }
    }
}


function test(){
    return {
        data: [
        {
            id: "99",
            user_id: "268",
            is_anonymous: "0",
            add_time: "1576225699",//⁮评论添加时间戳
            reply: "",
            title: "Great cover!",//评论标题
            content: "And very good price.",//评论内容
            rating: "5",//评论五星数量
            custom_name: "E.Pulliam",//用户名
            user: {
                avatar: "https://apifinde.imyfone.com/static/index/default/images/default-user-avatar.png",
                user_name_view: "E.Pulliam",
                add_time_date: "12/13/2019"
            },
            likes_num:[
                {
                like_num: 0,//点赞数量
                selected: true//是否选中点赞
                },
                {
                dislike_num: 0,//踩赞的数量
                selected: false//是否选中踩赞
                }
            ],
            imgs:[//用户评论图片
                {
                    resource: "https://finde.imyfone.com//static/upload/images/common/2019/11/27/1.jpg"
                },
                {
                    resource: "https://finde.imyfone.com/ic/upload/images/common/2019/11/27/2.jpg"
                }
            ]
        },
          {
            id: "100",
            user_id: "263",
            is_anonymous: "1",
            add_time: "1572402231",//⁮评论添加时间戳
            reply: "",
            title: "easy to install",//评论标题
            content: "So far Its been a great protector and its easy to install!",//评论内容
            rating: "2",//评论五星数量
            custom_name: "A.J",//用户名
            user: {
                avatar: "https://apifinde.imyfone.com/static/index/default/images/default-user-avatar.png",
                user_name_view: "E.Pulliam",
                add_time_date: "02/12/2020"
            },
            likes_num:[
                {
                like_num: 0,//点赞数量
                selected: false//是否选中点赞
                },
                {
                dislike_num: 2,//踩赞的数量
                selected: true//是否选中踩赞
                }
            ],
            imgs:[//用户评论图片
                {
                    resource: "https://finde.imyfone.com//static/upload/images/common/2019/11/27/3.jpg"
                },
                {
                    resource: "https://finde.imyfone.com/ic/upload/images/common/2019/11/27/4.jpg"
                }
            ]
        },{
            id: "101",
            user_id: "223",
            is_anonymous: "0",
            add_time: "1575690226",//⁮评论添加时间戳
            reply: "",
            title: "Easy to install screen protector!",//评论标题
            content: "This one has the black edge compared to the clear ones I’m used to, but that’s not a problem at all. Easy to install and no bubbles!",//评论内容
            rating: "4",//评论五星数量
            custom_name: "N.K",//用户名
            user: {
                avatar: "https://apifinde.imyfone.com/static/index/default/images/default-user-avatar.png",
                user_name_view: "E.Pulliam",
                add_time_date: "02/12/2020"
            },
            likes_num:[
                {
                like_num: 1,//点赞数量
                selected: true//是否选中点赞
                },
                {
                dislike_num: 0,//踩赞的数量
                selected: false//是否选中踩赞
                }
            ],
            imgs:[//用户评论图片
                {
                    resource: "https://finde.imyfone.com//static/upload/images/common/2019/11/27/5.jpg"
                },
                {
                    resource: "https://finde.imyfone.com/ic/upload/images/common/2019/11/27/6.jpg"
                }
            ]
        }
    ]
}
}

// class User {
//     constructor(id, name, avatar){

//     }
// }


/*
{
    data: [{
            id: "99",
            user_id: "268",
            is_anonymous: "0",
            add_time: "1576225699", //⁮评论添加时间戳
            reply: "",
            title: "Great cover!",//评论标题
            content: "And very good price.",//评论内容
            rating: "5",//评论五星数量
            custom_name: "E.Pulliam",//用户名
            user: {
                avatar: "https://apifinde.imyfone.com/static/index/default/images/default-user-avatar.png",
                user_name_view: "E.Pulliam",
                add_time_date: "12/13/2019"
            },
            likes_num:[
                {
                like_num: 0,//点赞数量
                selected: true//是否选中点赞
                },
                {
                dislike_num: 0,//踩赞的数量
                selected: false//是否选中踩赞
                }
            ],
            imgs:[//用户评论图片
                {
                    resource: "https://finde.imyfone.com//static/upload/images/common/2019/11/27/1.jpg"
                },
                {
                    resource: "https://finde.imyfone.com/ic/upload/images/common/2019/11/27/2.jpg"
                }
            ]
        },{
            id: "100",
            user_id: "263",
            is_anonymous: "1",
            add_time: "1572402231",//⁮评论添加时间戳
            reply: "",
            title: "easy to install",//评论标题
            content: "So far Its been a great protector and its easy to install!",//评论内容
            rating: "2",//评论五星数量
            custom_name: "A.J",//用户名
            user: {
                avatar: "https://apifinde.imyfone.com/static/index/default/images/default-user-avatar.png",
                user_name_view: "E.Pulliam",
                add_time_date: "02/12/2020"
            },
            likes_num:[
                {
                like_num: 0,//点赞数量
                selected: false//是否选中点赞
                },
                {
                dislike_num: 2,//踩赞的数量
                selected: true//是否选中踩赞
                }
            ],
            imgs:[//用户评论图片
                {
                    resource: "https://finde.imyfone.com//static/upload/images/common/2019/11/27/3.jpg"
                },
                {
                    resource: "https://finde.imyfone.com/ic/upload/images/common/2019/11/27/4.jpg"
                }
            ]
        },
         {
            id: "101",
            user_id: "223",
            is_anonymous: "0",
            add_time: "1575690226",//⁮评论添加时间戳
            reply: "",
            title: "Easy to install screen protector!",//评论标题
            content: "This one has the black edge compared to the clear ones I’m used to, but that’s not a problem at all. Easy to install and no bubbles!",//评论内容
            rating: "4",//评论五星数量
            custom_name: "N.K",//用户名
            user: {
                avatar: "https://apifinde.imyfone.com/static/index/default/images/default-user-avatar.png",
                user_name_view: "E.Pulliam",
                add_time_date: "02/12/2020"
            },
            likes_num:[
                {
                like_num: 1,//点赞数量
                selected: true//是否选中点赞
                },
                {
                dislike_num: 0,//踩赞的数量
                selected: false//是否选中踩赞
                }
            ],
            imgs:[//用户评论图片
                {
                    resource: "https://finde.imyfone.com//static/upload/images/common/2019/11/27/5.jpg"
                },
                {
                    resource: "https://finde.imyfone.com/ic/upload/images/common/2019/11/27/6.jpg"
                }
            ]
        }
    ]
}*/